package ligapiwna.servlets.beerManagement;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import ligapiwna.model.dto.BeerDTO;
import ligapiwna.model.dto.BeerKindDTO;
import ligapiwna.model.services.BeerService;
import ligapiwna.model.services.impl.mock.BeerServiceMock;

/**
 * Servlet implementation class BeerLister
 */
public class BeerLister extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	private BeerService beerService;
	
	@Override
	public void init()
	{
		beerService = new BeerServiceMock();
	}
	
    /**
     * @see HttpServlet#HttpServlet()
     */
    public BeerLister() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		List<BeerDTO> beers = beerService.listBeers();
		List<BeerKindDTO> beerKinds = beerService.listBeerKinds();
		
		request.setAttribute("beers", beers);
		
		request.setAttribute("beerKinds", beerKinds);		
		
		RequestDispatcher view = request.getRequestDispatcher("beerManagement/beerList.jsp");
		view.forward(request, response);
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
